<?php
$numbers = [5, 3, 8, 1, 2];
$fruits = ["apple" => "苹果", "banana" => "香蕉", "orange" => "橙子"];

// 数组排序
sort($numbers);  // 升序排序
print_r($numbers);

rsort($numbers); // 降序排序
print_r($numbers);

// 关联数组排序
asort($fruits);  // 按值排序
print_r($fruits);

ksort($fruits);  // 按键排序
print_r($fruits);

// 数组操作
echo "数组长度：" . count($numbers) . "\n";
echo "最大值：" . max($numbers) . "\n";
echo "最小值：" . min($numbers) . "\n";
echo "总和：" . array_sum($numbers) . "\n";

// 数组合并
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];
$merged = array_merge($array1, $array2);
print_r($merged);

// 数组过滤
function isEven($num) {
    return $num % 2 == 0;
}
$evenNumbers = array_filter($numbers, "isEven");
print_r($evenNumbers);

// 数组映射
function double($num) {
    return $num * 2;
}
$doubledNumbers = array_map("double", $numbers);
print_r($doubledNumbers);
?>